<template>
  <div>
    <div>
      <el-table :data="purchases">
        <el-table-column prop="buyNumber" label="采购编号">
          <template slot-scope="scope">
            <el-link type="primary" @click="showDetail(scope.row.id)">{{scope.row.buyNumber}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="totalMoney" label="采购总金额(元)"></el-table-column>
        <el-table-column prop="totalNum" label="采购总数量"></el-table-column>
        <el-table-column prop="ptime" label="采购时间"></el-table-column>
        <el-table-column prop="user.uname" label="供应商"></el-table-column>
        <el-table-column label="采购单状态">
          <el-tag type="warning">供应商发货，等待签收</el-tag>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="audit(scope.row.id,2)">确认签收</el-button>
<!--            <el-button size="mini" type="danger" @click="audit(scope.row.id,0)">拒绝签收</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <div>
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageno"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
      <div>
        <show-details ref="showDetails"></show-details>
      </div>
    </div>
  </div>
</template>

<script>
    import ShowDetails from "../../../../liwentao/purchase/ShowDetails";
    export default {
        name: "purchaseOrderSigned",
        data(){
          return {
            purchases: [],
            purchase: {
              buyNumber: "",
              isShipments:1,//发货
              isAudit:1//审核通过
            },
            pageno: 1,
            pagesize: 5,
            total: 1
          }
        },
        methods:{
          getPurchases() {
            var params = new URLSearchParams();
            params.append("pageno", this.pageno);
            params.append("pagesize", this.pagesize);
            Object.keys(this.purchase).forEach(item => {
              params.append(item, this.purchase[item]);
            })
            this.$axios.get("purchase/purchase.action", {params: params})
              .then(res => {
                this.purchases = res.data.records;
                this.total = res.data.total;
              })
              .catch(err => {
                this.$message.error(err)
              })
          },
          showDetail(pid) {
            this.$refs.showDetails.dialogVisible = true;
            this.$refs.showDetails.purchaseDetail.pid = pid;
            this.$refs.showDetails.getData();
          },
          audit(id,isShipments){
            let purchaseInfo={
              id:id,
              isShipments:isShipments
            };
            //调用异步，对采购单进行状态修改
            this.$axios.put("purchase/purchaseOrderSigned.action",purchaseInfo)
              .then(res=>{
                if(res.data.x){
                  this.$message.success(res.data.msg);
                }else {
                  this.$message.error(res.data.msg);
                }
                //重新查询一次数据
                this.getPurchases();
              })
              .catch(err=>{
                this.$message.warning(err);
                alert(err);
              })
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getPurchases();
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getPurchases();
          }
        },
        created() {
          this.getPurchases();
        },
        components:{
          ShowDetails
        }
    }
</script>

<style scoped>

</style>
